<template>
  <div class="cookie-policy">
    <!-- 顶部横幅 -->
    <div class="policy-header">
      <div class="header-content">
        <h1>Cookie 政策</h1>
        <p>了解我们如何使用 Cookie 改善您的体验</p>
      </div>
      <div class="header-graphics">
        <div class="graphic-element"></div>
      </div>
    </div>

    <!-- 主要内容 -->
    <div class="policy-container">
      <!-- 左侧导航 -->
      <nav class="policy-nav">
        <div v-for="(section, index) in sections" 
             :key="index"
             class="nav-item"
             :class="{ active: currentSection === index }"
             @click="scrollToSection(index)">
          <i :class="section.icon"></i>
          {{ section.title }}
        </div>
      </nav>

      <!-- 中间内容区 -->
      <main class="policy-content">
        <div v-for="(section, index) in sections" 
             :key="index"
             :id="'section-' + index"
             class="content-section">
          <div class="section-header">
            <i :class="section.icon"></i>
            <h2>{{ section.title }}</h2>
          </div>
          <div class="section-body" v-html="section.content"></div>
        </div>
      </main>

      <!-- 右侧工具栏 -->
      <aside class="policy-tools">
        <div class="cookie-preferences">
          <h3>Cookie 偏好设置</h3>
          <div class="preference-options">
            <div class="preference-item">
              <div class="preference-header">
                <span>必要的 Cookie</span>
                <el-switch v-model="cookiePreferences.necessary" disabled></el-switch>
              </div>
              <p>这些 Cookie 对网站的基本功能是必需的</p>
            </div>
            
            <div class="preference-item">
              <div class="preference-header">
                <span>分析 Cookie</span>
                <el-switch v-model="cookiePreferences.analytics"></el-switch>
              </div>
              <p>帮助我们了解用户如何使用网站</p>
            </div>
            
            <div class="preference-item">
              <div class="preference-header">
                <span>功能 Cookie</span>
                <el-switch v-model="cookiePreferences.functional"></el-switch>
              </div>
              <p>提供更多个性化的功能</p>
            </div>
          </div>
          
          <div class="preference-actions">
            <button class="save-preferences" @click="savePreferences">
              保存设置
            </button>
          </div>
        </div>

        <div class="last-updated">
          <i class="fas fa-history"></i>
          最后更新: 2024-03-15
        </div>
      </aside>
    </div>
  </div>
</template>

<script>
export default {
  name: 'CookiePolicy',
  
  data() {
    return {
      currentSection: 0,
      cookiePreferences: {
        necessary: true,
        analytics: true,
        functional: true
      },
      sections: [
        {
          title: 'Cookie 概述',
          icon: 'fas fa-cookie-bite',
          content: `
            <p>Cookie 是存储在您设备上的小型文本文件。它们被广泛用于使网站正常运行或提供更高效的服务。</p>
            <h3>我们使用 Cookie 的目的</h3>
            <ul>
              <li>确保网站功能正常运行</li>
              <li>记住您的偏好设置</li>
              <li>提供个性化的用户体验</li>
              <li>帮助我们了解网站的使用情况</li>
            </ul>
          `
        },
        {
          title: 'Cookie 类型',
          icon: 'fas fa-th-list',
          content: `
            <h3>必要的 Cookie</h3>
            <p>这些 Cookie 对于网站的基本功能是必需的，不能被禁用。</p>
            
            <h3>分析 Cookie</h3>
            <p>帮助我们了解访问者如何使用网站，以便我们可以改进网站体验。</p>
            
            <h3>功能 Cookie</h3>
            <p>这些 Cookie 使网站能够记住您做出的选择，提供增强的个性化功能。</p>
          `
        },
        {
          title: '管理 Cookie',
          icon: 'fas fa-sliders-h',
          content: `
            <h3>如何控制 Cookie</h3>
            <p>您可以通过以下方式管理 Cookie：</p>
            <ul>
              <li>使用网站提供的 Cookie 设置</li>
              <li>通过浏览器设置</li>
              <li>访问 www.aboutcookies.org 获取更多信息</li>
            </ul>
          `
        },
        {
          title: '第三方 Cookie',
          icon: 'fas fa-external-link-alt',
          content: `
            <h3>第三方服务</h3>
            <p>我们的网站使用以下第三方服务：</p>
            <ul>
              <li>Google Analytics - 用于网站分析</li>
              <li>社交媒体插件</li>
              <li>广告服务</li>
            </ul>
          `
        }
      ]
    }
  },

  methods: {
    scrollToSection(index) {
      this.currentSection = index;
      const element = document.getElementById(`section-${index}`);
      element.scrollIntoView({ behavior: 'smooth' });
    },

    savePreferences() {
      // 实现保存 Cookie 偏好的逻辑
      console.log('Saving preferences:', this.cookiePreferences);
      this.$message({
        message: 'Cookie 偏好设置已保存',
        type: 'success'
      });
    }
  },

  mounted() {
    // 监听滚动以更新当前章节
    const observer = new IntersectionObserver((entries) => {
      entries.forEach(entry => {
        if (entry.isIntersecting) {
          const sectionId = entry.target.id;
          this.currentSection = parseInt(sectionId.split('-')[1]);
        }
      });
    }, { threshold: 0.5 });

    this.sections.forEach((_, index) => {
      const element = document.getElementById(`section-${index}`);
      if (element) observer.observe(element);
    });
  }
}
</script>

<style scoped>
/* 在最前面添加这些全局重置样式 */
ul, li {
  list-style: none !important;
  margin: 0 !important;
  padding: 0 !important;
}

.cookie-policy {
  min-height: 100vh;
  background: #f8f9fa;
}

.policy-header {
  background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
  color: white;
  padding: 4rem 2rem;
  position: relative;
  overflow: hidden;
}

.header-content {
  max-width: 1200px;
  margin: 0 auto;
  position: relative;
  z-index: 1;
}

.header-content h1 {
  font-size: 3rem;
  font-weight: 700;
  margin-bottom: 1rem;
}

.header-graphics {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 50%;
  overflow: hidden;
}

.graphic-element {
  position: absolute;
  width: 1000px;
  height: 1000px;
  background: radial-gradient(circle at center, 
    rgba(255,255,255,0.1) 0%,
    transparent 70%);
  top: -50%;
  right: -50%;
  animation: rotate 30s linear infinite;
}

.policy-container {
  max-width: 1400px;
  margin: -50px auto 0;
  padding: 0 2rem;
  display: grid;
  grid-template-columns: 250px 1fr 300px;
  gap: 2rem;
  position: relative;
}

.policy-nav {
  background: white;
  border-radius: 12px;
  padding: 1.5rem;
  position: sticky;
  top: 2rem;
  height: fit-content;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.nav-item {
  padding: 0.75rem 1rem;
  margin: 0.5rem 0;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.nav-item:hover {
  background: rgba(59, 130, 246, 0.05);
  color: #3b82f6;
}

.nav-item.active {
  background: #3b82f6;
  color: white;
}

.policy-content {
  background: white;
  border-radius: 12px;
  padding: 2rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.content-section {
  margin-bottom: 3rem;
}

.section-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.section-header h2 {
  font-size: 1.8rem;
  color: #3b82f6;
}

.section-body {
  color: #333;
  line-height: 1.6;
}

.section-body h3 {
  font-size: 1.4rem;
  color: #3b82f6;
  margin: 1.5rem 0 1rem;
}

.section-body ul {
  margin: 1rem 0;
  padding-left: 1.5rem;
}

.section-body li {
  margin: 0.5rem 0;
}

.policy-tools {
  position: sticky;
  top: 2rem;
  height: fit-content;
}

.cookie-preferences {
  background: white;
  border-radius: 12px;
  padding: 1.5rem;
  margin-bottom: 1rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.cookie-preferences h3 {
  font-size: 1.2rem;
  color: #3b82f6;
  margin-bottom: 1.5rem;
}

.preference-options {
  display: grid;
  gap: 1.5rem;
}

.preference-item {
  border-bottom: 1px solid #eee;
  padding-bottom: 1rem;
}

.preference-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.preference-item p {
  color: #666;
  font-size: 0.9rem;
}

.preference-actions {
  margin-top: 1.5rem;
  text-align: center;
}

.save-preferences {
  width: 100%;
  padding: 0.75rem;
  background: #3b82f6;
  color: white;
  border: none;
  border-radius: 8px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
}

.save-preferences:hover {
  background: #2563eb;
  transform: translateY(-2px);
}

.last-updated {
  background: white;
  border-radius: 12px;
  padding: 1.5rem;
  color: #666;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

@keyframes rotate {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

/* 响应式调整 */
@media (max-width: 1200px) {
  .policy-container {
    grid-template-columns: 200px 1fr;
  }
  
  .policy-tools {
    display: none;
  }
}

@media (max-width: 768px) {
  .policy-container {
    grid-template-columns: 1fr;
    padding: 1rem;
  }
  
  .policy-nav {
    display: none;
  }
  
  .header-content h1 {
    font-size: 2rem;
  }
}

/* 修改列表样式 */
.section-content ul {
  margin: 1rem 0;
  padding-left: 0;
  list-style: none;
}

.section-content li {
  margin: 0.75rem 0;
  padding-left: 1.5rem;
  position: relative;
  line-height: 1.6;
}

/* 添加自定义前缀图标 */
.section-content li::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0.5rem;
  width: 6px;
  height: 6px;
  background: #3b82f6;
  border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
  transition: all 0.3s ease;
}

/* 添加悬浮效果 */
.section-content li:hover {
  transform: translateX(5px);
  background: rgba(59, 130, 246, 0.05);
  border-radius: 4px;
  padding: 0.5rem 1rem 0.5rem 2rem;
}

.section-content li:hover::before {
  background: #2563eb;
  transform: scale(1.2);
}

/* 美化标题样式 */
.content-section h2 {
  font-size: 2rem;
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  padding-bottom: 1rem;
  margin-bottom: 2rem;
  border-bottom: 2px solid #e3f2fd;
}

.content-section h3 {
  font-size: 1.5rem;
  color: #3b82f6;
  margin: 2rem 0 1rem;
  position: relative;
  padding-left: 1rem;
}

.content-section h3::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: linear-gradient(to bottom, #3b82f6, #2563eb);
  border-radius: 2px;
}

/* 添加卡片悬浮效果 */
.content-section {
  transition: all 0.3s ease;
}

.content-section:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
}
</style> 